package cn.jxwazx.sheinspringboot.controller;


import cn.jxwazx.sheinspringboot.entity.R;
import cn.jxwazx.sheinspringboot.entity.param.ProductPageParam;
import cn.jxwazx.sheinspringboot.entity.po.ProductList;
import cn.jxwazx.sheinspringboot.entity.vo.ActiveVo;
import cn.jxwazx.sheinspringboot.entity.vo.GMVVo;
import cn.jxwazx.sheinspringboot.service.ProductListService;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import java.util.List;
import lombok.RequiredArgsConstructor;
import org.apache.commons.compress.utils.Lists;
import org.dromara.hutool.core.text.StrUtil;
import org.springframework.context.annotation.Lazy;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequiredArgsConstructor(onConstructor_ = {@Lazy})
@RequestMapping("/home")
public class HomeController {

    private final ProductListService productListService;

    /**
     * 展示GMV
     *
     * @return
     */
    @PostMapping("/gmv")
    public Object gmv() {
        List<GMVVo> list = productListService.selectGMV();
        return R.success(list);
    }


    /**
     * 展示活跃产品数量
     *
     * @return
     */
    @PostMapping("/active")
    public Object active() {
        List<ActiveVo> list = productListService.active();
        return R.success(list);
    }

    /**
     * 展示不活跃产品数量
     *
     * @return
     */
    @PostMapping("/notActiveList")
    public Object notActiveList(@RequestBody ProductPageParam param) {
        Page<ProductList> page = productListService.filterProduct(param)
                .eq(ProductList::getNearSaleCountInt,0)
                .page(param.getPage());
        return R.successPage(page);
    }


     /**
     * 展示活跃产品列表
     *
     * @return
     */
    @PostMapping("/activeList")
    public Object activeList(@RequestBody ProductPageParam param) {
        Page<ProductList> page = productListService.filterProduct(param)
                .gt(ProductList::getNearSaleCountInt,0)
                .page(param.getPage());
        return R.successPage(page);
    }

}
